<html xmlns:th="http://www.thymeleaf.org"  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="roleDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="roleToolbar" style="display: none;">
    <div th:if="${@sec.hasPermission('car:add')}">
        <a onclick="CarList.addFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'glyphicon-plus icon-green'">添加</a>
    </div>
</div>

<script type="text/javascript" th:inline="javascript">
    var CarList={
      addFun:function(){
          parent.$.modalDialog({
              title : '添加',
              width : 450,
              height : 300,
              href : basePath + '/car/infoTree',
              buttons : [ {
                  text : '确定',
                  handler : function() {
                      parent.$.modalDialog.openner_dataGrid = roleDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                      var f = parent.$.modalDialog.handler.find('#roleAddForm');
                      f.submit();
                  }
              } ]
          });
      }  ,
        editFun:function (id) {
                if (id === undefined) {
                    var rows = roleDataGrid.datagrid('getSelections');
                    id = rows[0].id;
                } else {
                    roleDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
                }
                parent.$.modalDialog({
                    title : '编辑',
                    width : 450,
                    height : 300,
                    href : basePath + '/role/editPage?id=' + id,
                    buttons : [ {
                        text : '确定',
                        handler : function() {
                            parent.$.modalDialog.openner_dataGrid = roleDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                            var f = parent.$.modalDialog.handler.find('#roleEditForm');
                            f.submit();
                        }
                    } ]
                });
        },/**
         * 删除
         */
        deleteFun:function (id) {
            if (id === undefined) {//点击右键菜单才会触发这个
                var rows = roleDataGrid.datagrid('getSelections');
                id = rows[0].id;
            } else {//点击操作里面的删除图标会触发这个
                roleDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
            }
            parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
                if (b) {
                    progressLoad();
                    $.post(basePath + '/role/delete', {
                        id : id
                    }, function(result) {
                        if (result.code === 1) {
                            parent.$.messager.alert('提示', result.msg, 'info');
                            roleDataGrid.datagrid('reload');
                        }
                        progressClose();
                    }, 'JSON');
                }
            });
        }
    };
    var roleDataGrid;
    $(function() {
        roleDataGrid = $('#roleDataGrid').datagrid({
            url : basePath + '/car/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            frozenColumns : [ [ {
                width : '100',
                title : '编号',
                field : 'id',
                sortable : true
            } ] ],
            columns : [ [ {
                width : '80',
                title : '名称',
                field : 'name',
                sortable : true
            } , {
                width : '80',
                title : '排序号',
                field : 'seq',
                sortable : true
            }, {
                width : '200',
                title : '描述',
                field : 'description'
            }, {
                field : 'iconCls',
                title : '图标',
                width : '200'
            }, {
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    /*[# th:if="${@sec.hasPermission('role:edit')}"]*/
                    str += $.formatString('<a href="javascript:void(0)" class="role-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'glyphicon-pencil icon-blue\'" onclick="CarList.editFun(\'{0}\');" >编辑</a>', row.id);
                    /*[/]*/
                    /*[# th:if="${@sec.hasPermission('role:delete')}"]*/
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="role-easyui-linkbutton-del" data-options="plain:true,iconCls:\'glyphicon-trash icon-red\'" onclick="CarList.deleteFun(\'{0}\');" >删除</a>', row.id);
                    /*[/]*/
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.role-easyui-linkbutton-ok').linkbutton({text:'授权'});
                $('.role-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.role-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#roleToolbar'
        });
    });
</script>
</body>
</html>
